//
//  fatherClassifyViewController.m
//  LazyCat
//
//  Created by rocky on 15/12/29.
//  Copyright (c) 2015年 zhanshu. All rights reserved.
//

#import "fatherClassifyViewController.h"

@interface fatherClassifyViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong) NSMutableArray *arr;//所有父类的数组
@end

@implementation fatherClassifyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initNav:@"父类分级" doBack:YES];
    UIView *lineV = [[UIView alloc]initWithFrame:CGRectMake(0, 63, ScreenWidth, 1)];
    lineV.backgroundColor = [UIColor lightGrayColor];
    lineV.alpha = 0.2;
    [self.navBar addSubview:lineV];
    self.arr = [NSMutableArray array];
    for (int i = 0; i < self.faArr.count; i++) {
        [self.arr addObject:[self.faArr[i] objectForKey:@"categoryname"]];
    }
    [self createtableV];//创建表视图
}
-(void)createtableV {//创建表视图
    UITableView *tableV = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, ScreenWidth, ScreenHeight-64) style:UITableViewStyleGrouped];
    tableV.backgroundColor = BackColor;
    tableV.delegate = self;
    tableV.dataSource = self;
    [self.view addSubview:tableV];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.arr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
    if (cell == nil) {
        cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.text = [NSString stringWithFormat:@"%@",self.arr[indexPath.row]];
    cell.textLabel.font = [UIFont systemFontOfSize:16];
    UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth-45, 15, 30, 20)];
    if ([self.faStr isEqualToString:self.arr[indexPath.row]]) {
        imageV.image = [UIImage imageNamed:@"chanpin_cur"];
    }else {
        imageV.image = [UIImage imageNamed:@""];
    }
    [cell addSubview:imageV];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {//单元格行高
    return 50;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {//单元格头部的高度
    return 0.01;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {//点击方法
    NSString *name = self.arr[indexPath.row];
    NSString *idf = [self.faArr[indexPath.row] objectForKey:@"categoryid"];
    [self.delegate backFuStr:name identify:idf];
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
@end
